package com.mapper;

import com.bean.Article;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Yuicon on 2017/3/20.
 */
@Repository
public interface ArticleMapper {

    @Select("select id,title,synopsis,content,user_id as userId from tb_article where id = #{id}")
    Article findById(String id);

    @Select("select id,title,synopsis,content,user_id as userId from tb_article")
    List<Article> findAll();

    @Select("select id,title,synopsis,content from tb_article where user_id = #{userId}")
    List<Article> findByUserId(String userId);

    @Insert("insert into tb_article (id,title,synopsis,content,user_id) " +
            "values(#{id},#{title},#{synopsis},#{content},#{userId})")
    int insert(Article article);

    @Delete("delete from tb_article where id = #{id}")
    int deleteById(String id);

    @Update("update tb_article set content = #{content}, title = #{title} where id = #{id}")
    int update(Article article);

}
